<?
  $id        = 0;
  $name      = null;
  $description  = null;
  $start_date    = null;
  $end_date    = null;
  $pic_id      = null;
  $published    = true;
  
  
  if(isset($this->season)){
    $id      = $this->season->id;
    $name    = $this->season->name;
    $description= $this->season->description;
    $start_date = $this->season->start_date;
    $end_date   = $this->season->end_date;
    $published  = $this->season->published;
  }
  
  $pic_id        = null;
  $pic_flickr_id = null;
  $pic_url       = null;
  if($this->season_pic){
    $pic_id        = $this->season_pic->id;
    $pic_flickr_id = $this->season_pic->flickr_id;
    $pic_url       = PBNYHelper::getFlickrImageUrl($pic_flickr_id);
  }
  
  $season_divisions = array();
  $divisions        = array();
  if(isset($this->divisions))  
    $divisions = $this->divisions;
  if(isset($this->season_divisions))
    $season_divisions = $this->season_divisions;
  
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<script type="text/javascript">
jQuery(document).ready(
  function(){
    jQuery("#adminForm").validate({
      rules:  {
        name: "required",
        start_date: {
          required: true,
          date: true
        },
        end_date: {
          required: true,
          date: true
        }
      }
    });
  }
);
</script>
  <fieldset class="adminform">
    <legend>Details</legend>
    <table class="admintable" width="100%">
      <tr>
        <td></td>
        <td><img src="<?= PBNYHelper::getFlickrImageUrl($pic_flickr_id) ?>"/></td>
      </tr>
      <tr>
        <td class="key">URL</td>
        <td>
          <input type="hidden" id="old_pic_url" name="old_pic_url" value="<?= $pic_url ?>"/>
          <input type="hidden" id="pic_flickr_id" name="pic_flickr_id" value="<?= $pic_flickr_id ?>"/>
          <textarea id="pic_url" name="pic_url" rows="2" cols="40"><?= $pic_url ?></textarea>
        </td>
      </tr>
      <tr>
        <td class="key">Name</td>
        <td>
          <input type="text" name="name" id="name" value="<?= $name; ?>" />
        </td>
      </tr>
      <tr>
        <td class="key">Description</td>
        <td>
          <?= $this->editor->display( 'description', $description, '100%', '480', '80', '15'  ) ?>
        </td>          
      </tr>
      <tr>
        <td class="key">Start Date</td>
        <td>
          <?= JHTML::calendar($start_date, "start_date", "start_date") ?>
        </td>
      </tr>
      <tr>
        <td class="key">End Date</td>
        <td>
          <?= JHTML::calendar($end_date, "end_date", "end_date") ?>
        </td>
      </tr>        
      <tr>
        <td class="key">Published</td>
        <td>
          <?= JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $published); ?>
        </td>
      </tr>
     </table>
   </fieldset>
   <fieldset>
    <legend>Relationship</legend>
    <table class="admintable">
      <tr>
        <td class="key">Season Divisions</td>
        <td>
          <?
            $sdivisions = array();
            if(is_array($season_divisions)){
              foreach($season_divisions as $season_division)
                array_push($sdivisions, $season_division->division_id);
            }
          ?>
          <?= JHTML::_('select.genericlist', $divisions, 'divisions[]', 'multiple=multiple size=10', 'id', 'name', $sdivisions); ?>
        </td>
      </tr>
    </table>
   </fieldset>
   <input type="hidden" name="option" value="<?= JRequest::getVar( 'option' );?>"/>
   <input type="hidden" name="c" value="<?= JRequest::getVar('c', 'season'); ?>" />
   <input type="hidden" name="id" value="<?= $id; ?>"/>      
   <input type="hidden" name="pic_id" value="<?= $pic_id; ?>"/>
   <input type="hidden" name="task" value=""/>
</form>
